Adding configurable compiler plugins for Bazel builds.#23212
Open
Adding configurable compiler plugins for Bazel builds.#23212
Conversation
maxbartel
reviewed
Jan 21, 2026
Contributor
maxbartel
left a comment
There was a problem hiding this comment.
The plugin infra looks solid. I have a suggestion on how to import torch-mlir though. Pretty cool!
krzysz00
reviewed
Jan 21, 2026
Contributor
krzysz00
left a comment
There was a problem hiding this comment.
As a comment, can we get similar autodetection of whether there's a Vulkan SDK installed?
... and as a followup, if there'll be such autodetection, it might make sense to detect the gfx number of the running machine so that we can build e2e tests and the like? But that's probably a subsequent PR
ScottTodd
reviewed
Jan 22, 2026
13f7a0c to
c562954
Compare
c562954 to
1e8f4cc
Compare
Collaborator
Author
|
feedback addressed and vulkan sdk check added |
Replace the hardcoded Bazel StaticLinkedPlugins.inc contents with a generated registry driven by //compiler/plugins:enabled_plugins and the --iree_compiler_plugins alias. This mirrors the runtime driver selection model while preserving the existing default plugin set for plain Bazel invocation. Teach iree-bazel-configure/configure_bazel.py to resolve IREE_COMPILER_PLUGINS, including all/exclusion syntax, from buildable local inputs. The wrapper defaults to all buildable plugins so developer builds pick up optional inputs such as Torch when the submodule is initialized, while explicit plugin lists fail on unknown or unavailable entries. CUDA selection also records the repository env var consumed by @iree_cuda so plugin selection and external repository configuration agree. Make the compiler plugin registry root-loadable so a downstream Bazel root can provide its own default_compiler_plugins.bzl and register out-of-tree plugins without editing IREE. Align MLIR-adjacent source repositories with the existing LLVM ownership model: IREE creates bundled LLVM, StableHLO, and torch-mlir sources when it is the root module, while downstream roots can provide their own repositories and configure torch-mlir through its upstream Bazel overlay. Add Bazel wiring for the Torch input plugin. This lets Bazel-built tools link input_torch and process Torch dialect input through the same conversion paths covered by the existing lit tests. Those tests are only compatible with tools built with input_torch enabled, and the generated CMake preserves the same option guard. Teach bazel_to_cmake to preserve supported compiler-plugin compatibility selects, alongside the existing platform selects, so generated CMake does not silently drop option-gated lit tests. Declare the LLVMIR translation helper's dialect translation dependencies on the helper target itself, matching the headers it includes instead of relying on consumers to expose incidental MLIR translation libraries. Detect Vulkan SDK installs during Bazel configuration and persist the normalized VULKAN_SDK repository environment for LLVM's Vulkan SDK repository rule when available.
1e8f4cc to
25c54e5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements configurable static compiler plugin selection for Bazel builds. Previously, Bazel hardcoded the contents of
StaticLinkedPlugins.inc, so every Bazel-built compiler tool linked the same fixed plugin set with no supported way to exclude unavailable toolchains, speed up local iteration, or add downstream compiler plugins.The core mechanism mirrors the shape of the existing Bazel HAL driver selection:
//compiler/plugins:enabled_pluginsis astring_list_flag, exposed through the--iree_compiler_pluginsalias, andcompiler/plugins/plugins.bzlgenerates the per-plugin config settings,.incfragments, and aggregate dependency targets consumed bycompiler/src/iree/compiler/PluginAPI/Config.iree-bazel-configurenow resolvesIREE_COMPILER_PLUGINSfrom the local environment. It supports:IREE_COMPILER_PLUGINS=allfor every buildable plugin.IREE_COMPILER_PLUGINS=all,-plugin_idfor all buildable plugins except selected exclusions.IREE_COMPILER_PLUGINS=plugin_a,plugin_bfor explicit selection.The wrapper defaults to
allso local developer builds get a batteries-included compiler when the relevant SDKs and submodules are available. Explicit plugin selections fail loudly when a requested plugin is unknown or cannot be built.Toolchain and SDK detection now covers:
IREE_CUDA_TOOLKIT_ROOT,IREE_CUDA_DEPS_DIR, common CUDA environment variables, andnvccdiscovery, with the selected repository environment persisted for@iree_cuda.ROCM_PATH,ROCM_ROOT,ROCM_HOME,HIP_PATH, andhipcc.@vulkan_sdk//:sdkrepository rule, usingVULKAN_SDK,vulkaninfo, and common SDK install locations.The Torch input plugin is now wired into Bazel. Bazel-built tools can link
input_torchand process Torch dialect input through the existing Torch input conversion tests. The implementation uses torch-mlir's upstream Bazeltorch_mlir_configurerule instead of carrying a copied overlay implementation. The Torch InputConversion CMake files are also generated from their BUILD files; the root Torch CMake file remains hand-maintained because it owns CMake-only torch-mlir vendor setup and plugin registration.The plugin registry is also root-loadable for out-of-tree users.
//compiler/pluginsloads@//build_tools/bazel:default_compiler_plugins.bzl, so a downstream Bazel root can provide that file to register additional compiler plugins, replace registration targets, or choose different default plugin IDs without editing IREE. In the same spirit, IREE now creates bundled LLVM, StableHLO, and torch-mlir source repositories only when IREE is the root module; downstream roots can provide their own MLIR-adjacent repositories.This PR intentionally does not add GPU architecture autodetection. Vulkan SDK discovery is just enough to make LLVM's Vulkan SDK repository rule work when a local SDK is available; choosing GPU-specific target defaults should be a separate policy discussion.
Validation performed locally:
iree-bazel-configureiree-bazel-build //compiler/src/iree/compiler/PluginAPI/Config:StaticLinkedPluginsiree-bazel-build //tools:iree-compileiree-bazel-build //compiler/src/iree/compiler/PluginAPI/Config:StaticLinkedPlugins --iree_compiler_plugins=hal_target_llvm_cpu,input_tosabazel cquerychecks confirming disabled Torch/StableHLO plugins are absent from the configured graphiree-bazel-test //compiler/plugins/... --test_output=errorspre-commit run --allgit diff --check